package cn.aifeix.org.service.impl;

import cn.aifeix.basic.service.impl.BaseServiceImpl;
import cn.aifeix.org.domain.DictionaryDetail;
import cn.aifeix.org.domain.DictionaryType;
import cn.aifeix.org.mapper.DictionaryDetailMapper;
import cn.aifeix.org.mapper.EmployeeMapper;
import cn.aifeix.org.service.DictionaryDetailService;
import cn.aifeix.org.service.DictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DictionaryDetailServiceImpl extends BaseServiceImpl<DictionaryDetail> implements DictionaryDetailService {

    @Autowired
    private DictionaryDetailMapper dictionaryDetailMapper;
    @Override
    public List<DictionaryDetail> findByTypeId(Long typeId) {
        return dictionaryDetailMapper.findByTypeId(typeId);
    }

//    @Autowired
//    private DictionaryTypeMapper dictionaryTypeMapper;
//
//
//    @Override
//    public List<DictionaryType> deptTree() {
//        List<DictionaryType> result = new ArrayList<>();
//        List<DictionaryType> allDepts = dictionaryTypeMapper.findAll();
//        if (CollectionUtils.isEmpty(allDepts)){
//            return result;
//        }
//        // stream
//        Map<Long, DictionaryType> parentMap = allDepts.stream().collect(Collectors.toMap(DictionaryType::getId, e -> e));
//
//        // 遍历
//        for (DictionaryType dept : allDepts) {
//            if (null == dept.getParentId()) {
//                // 它就是最大的那个
//                result.add(dept);
//            } else {
//                // 当前的这个dept 是个儿子
//                DictionaryType parent = parentMap.get(dept.getParentId());
//                if (null == parent){
//                    break;
//                }
//                List<DictionaryType> children = parent.getChildren();
//                children.add(dept);
//            }
//        }
//        return result;
//    }
}
